package com.hmdp.config;

import cn.hutool.core.collection.CollectionUtil;
import com.hmdp.interceptor.LoginInterceptor;
import com.hmdp.interceptor.RefreshTokenInterceptor;
import com.hmdp.utils.RedisCache;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.annotation.Resource;
import java.util.List;

@Configuration
public class MvcConfig implements WebMvcConfigurer {

    @Resource
    private RedisCache redisCache;

    List<String> excludePathPatterns =
            CollectionUtil.newArrayList("/user/code", "/user/login",
                    "/blog/hot", "/shop/**", "/shop-type/**",
                    "/upload/**", "voucher/**");

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new RefreshTokenInterceptor(redisCache))
                .addPathPatterns("/**")
                .order(10);

        registry.addInterceptor(new LoginInterceptor())
                .excludePathPatterns(excludePathPatterns)
                .order(100);
    }

}
